home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP10.ZIP / CHAP10 / SCHMOO / IPERSTOR.CPP < prev    next >
C/C++ Source or Header  |  1993-06-13  |  7KB  |  273 lines

  1. /*
  2.  * IPERSTOR.CPP
  3.  * Schmoo Chapter 10
  4.  *
  5.  * Implementation of the IPersistStorage interface that we expose on the
  6.  * CSchmooFigure compound document object.  This ties into the functionality
  7.  * of CPolyline.
  8.  *
  9.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  10.  *
  11.  * Kraig Brockschmidt, Software Design Engineer
  12.  * Microsoft Systems Developer Relations
  13.  *
  14.  * Internet  :  kraigb@microsoft.com
  15.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  16.  */
  17.  
  18.  
  19. #include "schmoo.h"
  20.  
  21.  
  22. /*
  23.  * CImpIPersistStorage:CImpIPersistStorage
  24.  * CImpIPersistStorage::~CImpIPersistStorage
  25.  *
  26.  * Constructor Parameters:
  27.  *  pObj            LPCFigure associated with this object.
  28.  *  punkOuter       LPUNKNOWN of the controlling unknown.
  29.  */
  30.  
  31. CImpIPersistStorage::CImpIPersistStorage(LPCFigure pObj, LPUNKNOWN punkOuter)
  32.     {
  33.     m_cRef=0;
  34.     m_pObj=pObj;
  35.     m_punkOuter=punkOuter;
  36.     return;
  37.     }
  38.  
  39.  
  40. CImpIPersistStorage::~CImpIPersistStorage(void)
  41.     {
  42.     return;
  43.     }
  44.  
  45.  
  46.  
  47.  
  48. /*
  49.  * CImpIPersistStorage::QueryInterface
  50.  * CImpIPersistStorage::AddRef
  51.  * CImpIPersistStorage::Release
  52.  *
  53.  * Purpose:
  54.  *  Standard set of IUnknown members for this interface
  55.  */
  56.  
  57. STDMETHODIMP CImpIPersistStorage::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  58.     {
  59.     return m_punkOuter->QueryInterface(riid, ppv);
  60.     }
  61.  
  62. STDMETHODIMP_(ULONG) CImpIPersistStorage::AddRef(void)
  63.     {
  64.     ++m_cRef;
  65.     return m_punkOuter->AddRef();
  66.     }
  67.  
  68. STDMETHODIMP_(ULONG) CImpIPersistStorage::Release(void)
  69.     {
  70.     --m_cRef;
  71.     return m_punkOuter->Release();
  72.     }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /*
  79.  * CImpIPersistStorage::GetClassID
  80.  *
  81.  * Purpose:
  82.  *  Returns the CLSID of the object represented by this interface.
  83.  *
  84.  * Parameters:
  85.  *  pClsID          LPCLSID in which to store our CLSID.
  86.  *
  87.  * Return Value:
  88.  *  HRESULT         NOERROR on success, error code otherwise.
  89.  */
  90.  
  91. STDMETHODIMP CImpIPersistStorage::GetClassID(LPCLSID pClsID)
  92.     {
  93.     *pClsID=CLSID_Schmoo2Figure;
  94.     return NOERROR;
  95.     }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /*
  102.  * CImpIPersistStorage::IsDirty
  103.  *
  104.  * Purpose:
  105.  *  Tells the caller if we have made changes to this object since
  106.  *  it was loaded or initialized new.
  107.  *
  108.  * Parameters:
  109.  *  None
  110.  *
  111.  * Return Value:
  112.  *  HRESULT         Contains S_OK if we ARE dirty, S_FALSE if NOT dirty,
  113.  *                  that is, "Yes I AM dirty, or NO, I'm clean."
  114.  */
  115.  
  116. STDMETHODIMP CImpIPersistStorage::IsDirty(void)
  117.     {
  118.     return ResultFromScode(m_pObj->FIsDirty() ? S_OK : S_FALSE);
  119.     }
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. /*
  128.  * CImpIPersistStorage::InitNew
  129.  *
  130.  * Purpose:
  131.  *  Provides the object with the IStorage they can hold on to while
  132.  *  they are running.  Here we can initialize the structure of the
  133.  *  storage and AddRef it for incremental access.  This function will
  134.  *  only be called once in the object's lifetime in lieu of ::Load.
  135.  *
  136.  * Parameters:
  137.  *  pIStorage       LPSTORAGE for the object.
  138.  *
  139.  * Return Value:
  140.  *  HRESULT         NOERROR on success, error code otherwise.
  141.  */
  142.  
  143. STDMETHODIMP CImpIPersistStorage::InitNew(LPSTORAGE pIStorage)
  144.     {
  145.     return NOERROR;
  146.     }
  147.  
  148.  
  149.  
  150.  
  151.  
  152. /*
  153.  * CImpIPersistStorage::Load
  154.  *
  155.  * Purpose:
  156.  *  Instructs the object to load itself from a previously saved IStorage
  157.  *  that was handled by ::Save in another object lifetime.  This function
  158.  *  will only be called once in the object's lifetime in lieu of ::InitNew.
  159.  *  The object may hold on to pIStorage here for incremental access.
  160.  *
  161.  * Parameters:
  162.  *  pIStorage       LPSTORAGE from which to load.
  163.  *
  164.  * Return Value:
  165.  *  HRESULT         NOERROR on success, error code otherwise.
  166.  */
  167.  
  168. STDMETHODIMP CImpIPersistStorage::Load(LPSTORAGE pIStorage)
  169.     {
  170.     LONG    lRet;
  171.  
  172.     lRet=m_pObj->m_pPL->ReadFromStorage(pIStorage);
  173.  
  174.     if (lRet >= 0)
  175.         return NOERROR;
  176.  
  177.     return ResultFromScode(STG_E_READFAULT);
  178.     }
  179.  
  180.  
  181.  
  182.  
  183.  
  184. /*
  185.  * CImpIPersistStorage::Save
  186.  *
  187.  * Purpose:
  188.  *  Saves the data for this object to an IStorage which may
  189.  *  or may not be the same as the one previously passed to
  190.  *  ::Load, indicated with fSameAsLoad.
  191.  *
  192.  * Parameters:
  193.  *  pIStorage       LPSTORAGE in which to save our data.
  194.  *  fSameAsLoad     BOOL indicating if this is the same pIStorage
  195.  *                  that was passed to ::Load.  If it was, then
  196.  *                  objects that built up a structure in that storage
  197.  *                  do not have to regenerate the entire thing.
  198.  *
  199.  * Return Value:
  200.  *  HRESULT         NOERROR on success, error code otherwise.
  201.  */
  202.  
  203. STDMETHODIMP CImpIPersistStorage::Save(LPSTORAGE pIStorage, BOOL fSameAsLoad)
  204.     {
  205.     LONG    lRet;
  206.  
  207.     //fSameAsLoad is unimportant since we don't hold on to it.
  208.     lRet=m_pObj->m_pPL->WriteToStorage(pIStorage, VERSIONCURRENT);
  209.  
  210.     if (lRet >= 0)
  211.         return NOERROR;
  212.  
  213.     return ResultFromScode(STG_E_WRITEFAULT);
  214.     }
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221. /*
  222.  * CImpIPersistStorage::SaveCompleted
  223.  *
  224.  * Purpose:
  225.  *  Notifies the object that the storage in pIStorage has been completely
  226.  *  saved now.  This is called when the user of this object wants to
  227.  *  save us in a completely new storage, and if we normally hang on to
  228.  *  the storage we have to reinitialize ourselves here for this new one
  229.  *  that is now complete.
  230.  *
  231.  * Parameters:
  232.  *  pIStorage       LPSTORAGE of the new storage in which we now live.
  233.  *
  234.  * Return Value:
  235.  *  HRESULT         NOERROR on success, error code otherwise.
  236.  */
  237.  
  238. STDMETHODIMP CImpIPersistStorage::SaveCompleted(LPSTORAGE pIStorage)
  239.     {
  240.     return NOERROR;
  241.     }
  242.  
  243.  
  244.  
  245.  
  246.  
  247. /*
  248.  * CImpIPersistStorage::HandsOffStorage
  249.  *
  250.  * Purpose:
  251.  *  Instructs the object that another agent is interested in having total
  252.  *  access to the storage we might be hanging on to from ::InitNew or
  253.  *  ::SaveCompleted.  In this case we must release our hold and await
  254.  *  another call to ::SaveCompleted before we have a hold again.
  255.  *
  256.  *  Situations where this might happen arise in compound document scenarios
  257.  *  where this object might be in-place active but the application wants
  258.  *  to rename and commit the root storage.  Therefore we are asked to
  259.  *  close our hold, let the container party on the storage, then call us
  260.  *  again later to tell us the new storage we can hold.
  261.  *
  262.  * Parameters:
  263.  *  None
  264.  *
  265.  * Return Value:
  266.  *  HRESULT         NOERROR on success, error code otherwise.
  267.  */
  268.  
  269. STDMETHODIMP CImpIPersistStorage::HandsOffStorage(void)
  270.     {
  271.     return NOERROR;
  272.     }
  273.